import axios from '@/utils/request.js'

// 获取新闻详情
export function articlesGet (id) {
  return axios({
    url: '/v1_0/articles/' + id
  })
}

// 关注用户/取消关注用户
export function userFollowings (target, bol) {
  if (bol) {
    return axios({
      method: 'post',
      url: '/v1_0/user/followings',
      data: {
        target
      }
    })
  } else {
    return axios({
      method: 'delete',
      url: '/v1_0/user/followings/' + target
    })
  }
}

// 获取评论或评论回复
export function commentsGet (params) {
  return axios({
    url: '/v1_0/comments',
    params
  })
}

// 对文章点赞/取消对文章点赞
export function articleLikings (target, bol) {
  if (bol) {
    return axios({
      method: 'post',
      url: '/v1_0/article/likings',
      data: {
        target
      }
    })
  } else {
    return axios({
      method: 'delete',
      url: '/v1_0/article/likings/' + target
    })
  }
}

// 收藏文章/取消收藏文章
export function articleCollections (target, bol) {
  if (bol) {
    return axios({
      method: 'post',
      url: '/v1_0/article/collections',
      data: {
        target
      }
    })
  } else {
    return axios({
      method: 'delete',
      url: '/v1_0/article/collections/' + target
    })
  }
}

// 对文章或者评论进行评论
export function commentsPost (data) {
  return axios({
    method: 'post',
    url: '/v1_0/comments',
    data
  })
}
